package demo1enum;

//枚举类，也会独立一个生成字节码文件
// RED,BLACK,GREEN都是枚举对象
//下面方法默认继承Enum类，子类继承父类，要重写构造方法，默认调了，枚举是一个特殊的类
public enum TestEnum {
    RED(0.1,"红色"),
    BLACK(1.1,"黑色"),
    GREEN(2.1,"绿色");
    //给两个成员
    public double ordinal;
    public String color;

    //枚举的构造方法默认是私有的
    //枚举在类外不能调用，那么反射可以吗
    //不可以，枚举很安全，不支持反射
    private TestEnum(double ordinal,String color){

        this.ordinal= ordinal;
        this.color = color;
    }

    @Override
    public String toString() {
        return "TestEnum{" +
                "ordinal=" + ordinal +
                ", color='" + color + '\'' +
                '}';
    }

    public static void main(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++){
            System.out.print(testEnums[i] + " "+ testEnums[i].ordinal()+ " ");

        }
        System.out.println();

        TestEnum testEnum1 = TestEnum.valueOf("RED");
        System.out.println(testEnum1);

        System.out.println(BLACK.compareTo(GREEN));
    }



    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.BLACK;
        switch (testEnum){
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                System.out.println("颜色错误");
                break;
        }
    }
}
